package com.ktjiaoyu.t351.service;

import com.ktjiaoyu.t351.dao.UserDao;
import com.ktjiaoyu.t351.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName : UserServiceImpl
 * @Description :
 * @Author : Lzz
 * @Date: 2023/10/7 09:53:33
 */
@Service("userService")
public class UserServiceImpl implements UserService{

    @Autowired
    private UserDao userDao;

    @Override
    public List<User> findUserList() {
        return userDao.findUserList();
    }

    @Override
    @Transactional
    public boolean deleteUserById(int id) {
        boolean flag = false;
        if(userDao.deleteUserById(id) == 1){
            flag = true;
            //发生异常，进行事务回滚
            throw new RuntimeException("抛出运行时异常，测试spring事务...");
        }
        return flag;
    }
}
